home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991: Code Warrior / bincue / Code Warrior.bin / Developer Essentials / DTS Sample Code / System 7.0 Samples / CShell / IdleTasks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-21  |  3.5 KB  |  168 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:        CShell
  5. ** File:        idletasks.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "CShell.h"                /* Get the CShell includes/typedefs, etc.    */
  19. #include "CShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "CShell.protos"        /* Get the prototypes for CShell.            */
  21.  
  22. #ifndef __NOTIFICATION__
  23. #include <Notification.h>
  24. #endif
  25.  
  26. #ifndef __RESOURCES__
  27. #include <Resources.h>
  28. #endif
  29.  
  30. #ifndef __UTILITIES__
  31. #include <Utilities.h>
  32. #endif
  33.  
  34.  
  35.  
  36. /*****************************************************************************/
  37.  
  38.  
  39.  
  40. static Boolean        notifyActive = false;
  41. static NMRec        notifyTheUser = {
  42.     nil,        /* qLink */
  43.     nmType,        /* qType */
  44.     0,            /* nmFlags */
  45.     0L,            /* nmPrivate */
  46.     0,            /* nmReserved */
  47.     1,            /* nmMark */
  48.     nil,        /* nmIcon */
  49.     -1,            /* nmSound */
  50.     nil,        /* nmStr */
  51.     nil,        /* nmResp */
  52.     0L            /* nmRefCon */
  53. };
  54.  
  55. extern RgnHandle    gCurrentCursorRgn;
  56.  
  57.  
  58.  
  59. /*****************************************************************************/
  60. /*****************************************************************************/
  61.  
  62.  
  63.  
  64. #pragma segment Main
  65. void    DoIdleTasks(void)
  66. {
  67.     DynamicBalloonHelp();
  68. }
  69.  
  70.  
  71.  
  72. /*****************************************************************************/
  73.  
  74.  
  75.  
  76. /* MyIdleProc
  77. **
  78. ** This routine gets either an updateEvt, an activateEvt, a nullEvent or an
  79. ** OSEvent.  The first time called it will get a nullEvent; this is its chance
  80. ** to set the sleep value and mouseRegion that will be passed to WaitNextEvent
  81. ** by the caller within the AEM.  After that it will also get events of the
  82. ** other types (which are lost if masked out by the AEM) and must do with them
  83. ** whatever is appropriate.
  84. */
  85.  
  86. #pragma segment Main
  87. pascal Boolean    MyIdleProc(EventRecord *event, long *sleep, RgnHandle *mouseRgn)
  88. {
  89.     switch (event->what) {
  90.  
  91.         case updateEvt:
  92.         case activateEvt:
  93.         case kOSEvent:
  94.  
  95.             /* These events are passed by the AppleEvent manager to avoid
  96.                dropping while waiting for a reply or notification.  Every
  97.                procedure should handle these events in their idle procedure.
  98.                In this code, we simply dispatch these events back to the
  99.                main event loop handling code. */
  100.  
  101.             DoCursor(false, 0);
  102.             DoEvent(event);
  103.             break;
  104.  
  105.  
  106.         case nullEvent:
  107.  
  108.             /* The idle procedure is called once with the null event before
  109.                the loop begins.  This allows the application to alter sleep
  110.                time and mouseRgn to meet its own needs.  Since we're doing
  111.                nothing, set the cursor to a watch. */
  112.  
  113.             DoCursor(true, 'wait');
  114.  
  115.             *mouseRgn = gCurrentCursorRgn;
  116.             *sleep = 60;        /* This is just like the WaitNextEvent
  117.                                    sleeptime, so use the correct value for
  118.                                    your application.  It's better to use a
  119.                                    non-zero value here rather than zero,
  120.                                    as using zero really slows you down. */
  121.  
  122.             /* DoIdle(); */        /* Application's idle handling. */
  123.             break;
  124.  
  125.         default:
  126.             Alert(rErrorAlert, nil);
  127.             break;
  128.     }
  129.     return(false);
  130. }
  131.  
  132.  
  133.  
  134. /*****************************************************************************/
  135.  
  136.  
  137.  
  138. #pragma segment Main
  139. void    NotifyCancel(void)
  140. {
  141.     if (notifyActive) {
  142.         NMRemove((NMRecPtr)¬ifyTheUser);
  143.         notifyActive = false;
  144.     }
  145. }
  146.  
  147.  
  148.  
  149.  
  150. /*****************************************************************************/
  151.  
  152.  
  153.  
  154. #pragma segment Main
  155. void    NotifyUser(void)
  156. {
  157.     if (gInBackground) {
  158.         if (!notifyActive) {
  159.             notifyTheUser.nmIcon = GetResource('SICN', 128);
  160.             NMInstall(¬ifyTheUser);
  161.             notifyActive = true;
  162.         }
  163.     }
  164. }
  165.  
  166.  
  167.  
  168.